﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */

using System;

namespace PassBag.Logic.Backup {
    /// <summary>
    /// Represent a file entry on a ZipFile "Backup set"
    /// </summary>
    public class BackupZipEntry {
        private string _fileName = string.Empty;
        private string _comment = string.Empty;
        private const string ZIPENTRY_SEPARATOR = ".-.";

        /// <summary>
        /// Gets or sets the name of the backup zip entry.
        /// </summary>
        /// <value>The name of the file.</value>
        public string FileName {
            get {
                return _fileName;
            }
            set {
                _fileName = value;
            }
        }

        /// <summary>
        /// Gets or sets the comment of the BackupZipEntry.
        /// </summary>
        /// <value>The comment.</value>
        public string Comment {
            get {
                return _comment;
            }
            set {
                _comment = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BackupZipEntry"/> class.
        /// </summary>
        public BackupZipEntry () {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BackupZipEntry"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="comment">The comment.</param>
        public BackupZipEntry (string fileName, string comment) {
            this._fileName = fileName;
            this._comment = comment;
        }

        /// <summary>
        /// Gets a unique zip file entry using a Guid.
        /// </summary>
        /// <param name="backupEntryName">Name of the backup entry.</param>
        /// <returns></returns>
        public static string GetUniqueZipFileEntryName (string backupEntryName) {
            return string.Format ("{0}{1}{2}", Guid.NewGuid ().ToString ("D"), ZIPENTRY_SEPARATOR, backupEntryName);
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return _fileName.Replace(ZIPENTRY_SEPARATOR, "\t"); ;
        }
    }
}
